/*模拟删除确认函数：请开发人员重写删除操作函数*/
function del(msg,url){
	if(msg == 'msg'){
		msg = '确认删除吗？';
	}
	alert(msg);
}

function jump(url){
	location.href=url;
} 

function initPage(){
	//初始化主体内容区域的宽度
	var w = $(window).width();
	if (w < 1000) {
		if (document.documentElement.clientWidth < document.documentElement.offsetWidth-4){
			w = 1000;
		}else{
			w = 1000;		
		}
		
		$('#header_all').css('width',w+'px');
		$('#mininav').css('width',(w-10)+'px');
		$('#warp').css('width',w+'px');
		$('#footer').css('width',w+'px');
		$('body').attr('scroll','');
		$('body').css('overflow','');
		$('#content').css('width',(w-175)+'px');
	} else {
		$('#content').css('width', (w-175)+'px');
		$('#header_all').css('width','auto');
		$('#mininav').css('width','auto');
		$('#warp').css('width','auto');
		$('#footer').css('width','auto');
		$('body').attr('scroll','no');
		$('body').css('overflow','hidden');
	}
	$('#footer').remove();
	
	//初始化框架高度
	var h = $(window).height();
	$('#fmMainContents').height(h-100);
	$('#leftMenus').height(h-100);
	$('#openClose').height(h-100);
}

function _M(parentmenu){
	$("#leftMenus dl").load("?c=menu&a="+parentmenu,function(){
		initPage();
	});
}

function _MD(parentmenu){
	$("#leftMenus dl").load("?c=menudemo&a="+parentmenu,function(){
		initPage();
		if (parentmenu == 'welcome') {
			_MP('index.php?c=demo&a=welcome');
		}
	});
}
function _MP(targetUrl) {
	$("#fmMainContents").attr('src', targetUrl);
}

var NYUser = function () {
		this.userId = '';
		this.userNo = '';
		this.userName = '';
		this.unitId = '';
	};
var NYPatient = function () {
		this.id = 0;
		this.name = '';
		this.phone = '';
};

var NYCsm = function (){
	this.messager = new NYMessager();
	this.form = new NYForm();
};

// 对话框
NYCsm.prototype.openWindow = function (url, options) {
	var options = $.extend({title: 'CSM病人服务系统'}, options||{});
	window.top.art.dialog.open(url, options);
};
NYCsm.prototype.showMsg = function (content, options) {
	var settings = $.extend({
	    id: 'msg',
	    title: '温馨提示',
	    content: content,
	    width: 280,
	    height: 160,
	    left: '100%',
	    top: '100%',
	    fixed: true,
	    drag: false,
	    resize: false
	}, options);
	window.top.art.dialog(settings);
};
NYCsm.prototype.closeWindow = function (id) {
	if (id && window.top.art.dialog.list[id]) {
		window.top.art.dialog.list[id].close();
	} else {
		var list = window.top.art.dialog.list;
		for (var id in list) {
			list[id].close();
		}
	}
};
NYCsm.prototype.showBuyTip = function (msg) {
	if (!msg) {
		msg = '<div style="line-height: 22px; text-align: center;">对不起，请联系<font color=red>宁远科技</font>购买本模块功能，<br/>购买热线：400-11-91160</div>';
	}
	window.top.art.dialog({
		title:'购买提示',
		content:msg,
		width: 280,
		cancelVal: '关闭',
		cancel: true
	});
};
NYCsm.prototype.openAskForm = function (depid, docid) {
	JYCsm.openWindow(encodeURI('?c=feed&a=askform&name='+JYPatient.name+'&phone='+JYPatient.phone
			+'&uid='+JYPatient.id+'&depid='+depid+'&docid='+docid), 
			{width: 460, id: 'ask-form-dlg'});
};
NYCsm.prototype.openvisitinfo = function () {
	JYCsm.openWindow(encodeURI('?c=visit&a=visitinfo'), 
			{width: 900,height:450, id: 'visit-info-dlg'});
};
NYCsm.prototype.openFeedForm = function (depid, docid) {
	JYCsm.openWindow(encodeURI('?c=feed&a=feedform&name='+JYPatient.name+'&phone='+JYPatient.phone
			+'&uid='+JYPatient.id+'&depid='+depid+'&docid='+docid), 
			{width: 560, id: 'feed-form-dlg'});
};
NYCsm.prototype.openPatientForm = function () {
	JYCsm.openWindow('?c=patient&a=formdlg&'+'&pid='+JYPatient.id, 
			{width: 460, id: 'patient-form-dlg'});
};
NYCsm.prototype.openSurveyForm = function (qid, pid, name, phone) {
	if (!qid) {
		this.messager.error('本回访规则没有配置调查问卷');
	} else {
		var url = "index.php?c=quesnr&a=showquest&id="+qid+"&an=1&pid="+pid+"&phone="+phone+"&name="+encodeURI(name);
		window.open(url);
	}
};

// 消息提示框
var NYMessager = function (options) {
	this.settings = $.extend({
		title: '温馨提示'
	}, options);
};
NYMessager.prototype.error = function (msg) {
	window.top.art.dialog({title: this.settings.title, lock: true, content: msg, cancel: true, cancelVal:'关闭'});
};
NYMessager.prototype.succ = function (msg, options) {
	var settings = $.extend({
	    id: 'msg',
	    title: this.settings.title,
	    content: msg,
	    left: '100%',
	    top: '100%',
	    fixed: true,
	    drag: false,
	    resize: false,
	    time: 3
	}, options);
	window.top.art.dialog(settings);
};

// ajaxForm提交
var NYForm = function () {
	this.settings = {
		formSelector: '#ajax-form',
		dlgId: '',
		action: null,
		dataType: 'json',
		beforeSubmit: null,
		callback: null
	};
};
NYForm.prototype.ajaxPost = function (options) {
	this.settings = $.extend(this.settings, options);
	var $form = $(this.settings.formSelector);

	var doPost = true;
	if (this.settings.beforeSubmit) {
		doPost = this.settings.beforeSubmit($form);
	}
	if (!doPost) return;
	var data = $form.serializeArray();
	for (var prop in options.data) {
		data.push({name:prop, value: options.data[prop]});
	}
	if (!options.action) {
		options.action = $form.attr('action');
	}
	var self = this;
	$.post(options.action, data, function (rsp, status, xhr) {
		if (self.settings.dataType == 'json') {
			if (rsp.code > 0) {
				JYCsm.messager.succ(rsp.msg);
				if (self.settings.dlgId) {
					JYCsm.closeWindow(self.settings.dlgId);
				}
			} else if (rsp.msg) {
				JYCsm.messager.error(rsp.msg);
			}
		}
		if (self.settings.callback) self.settings.callback(rsp, status, xhr);
	}, this.settings.dataType);
};

var JYCsm = new NYCsm();